package cn.edu.neusoft.yyd208.foodorder.activity;

import android.content.Intent;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import java.util.List;

import cn.edu.neusoft.yyd208.foodorder.R;
import cn.edu.neusoft.yyd208.foodorder.adapter.UserCommentAdapter;
import cn.edu.neusoft.yyd208.foodorder.bean.CommentFoodBean;
import cn.edu.neusoft.yyd208.foodorder.listener.ListListener;
import cn.edu.neusoft.yyd208.foodorder.model.UserCommentModel;

public class UserCommentActivity extends BaseActivity {
    RecyclerView recyclerView;
    List<CommentFoodBean> items;
    String userid;
    TextView tv_wcomment;
    ListListener<CommentFoodBean> userCommentListener=new ListListener<CommentFoodBean>() {
        @Override
        public void onResponse(List<CommentFoodBean> list) {
            items=list;
            UserCommentAdapter myAdapter=new UserCommentAdapter(UserCommentActivity.this,items,R.layout.comment);
            recyclerView.setAdapter(myAdapter);
            recyclerView.setItemAnimator(new DefaultItemAnimator());
        }

        @Override
        public void onFail(String msg) {
            showToast("error");
        }
    };

    @Override
    void initView() {
        setLayout_file(R.layout.activity_user_comment);
        tv_wcomment=(TextView)findViewById(R.id.tv_wcomment);
        recyclerView =(RecyclerView)findViewById(R.id.commentRecycler);
        LinearLayoutManager linearLayoutManager=new LinearLayoutManager(this);
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(linearLayoutManager);

    }

    @Override
    void initEvent() {
        tv_wcomment.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(UserCommentActivity.this,FoodInfoActivity.class);
                startActivityForResult(intent,1);
            }
        });

    }

    @Override
    void initData() {
        userid=getUser_userid();
        UserCommentModel userCommentModel=new UserCommentModel();
        userCommentModel.getFoodMessage(userid,userCommentListener);
    }

}
